package com.apexsoft.margin.account.management.api.http;



import com.apexsoft.margin.account.management.condition.FirstChainCondition;
import com.apexsoft.margin.account.management.condition.PreChainCondition;
import com.apexsoft.margin.account.management.condition.SecondChainCondition;
import com.apexsoft.margin.account.management.domain.common.model.AdapterResp;
import com.apexsoft.margin.account.management.domain.common.model.AdapterRespChild;
import com.apexsoft.margin.account.management.domain.common.model.Pagination;
import com.apexsoft.margin.account.management.domain.search.model.*;
import com.apexsoft.margin.account.management.domain.search.model.response.PreChainSearchOutputDomain;
import com.apexsoft.margin.account.management.domain.search.model.response.SecondChainSearchOutputDomain;
import com.apexsoft.margin.account.management.util.DealResp;
import com.apexsoft.margin.account.management.util.ResultUtil;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/commSearch")
public class CommSearchController {
    @RequestMapping("/firstChainInfo")
    public ResultUtil getFitstChainInfo(@RequestBody FirstChainCondition condition){
        ResultUtil resultUtil = new ResultUtil();
        Pagination page = condition.getPage();
        FirstChainCondition.Condition domain = condition.getCondition();
        if(page==null){
            page = new Pagination(1,10);
        }
        if(page.getCurrent()==null){
            page.setCurrent(1);
        }
        if(page.getPageSize()==null){
            page.setPageSize(10);
        }
        List<FirstChainSearch> list = new ArrayList<>();
        if (domain.getG_funcid() != null) {
            for (int i = 0; i < 20; i++) {
                FirstChainSearch chainSearch = new FirstChainSearch("序号：" + i, "2", "3", "4", 5444L, "6", "7", 8, 9, 10, 11, 12, 13, 14, "15", 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, "30", "31", "32", "33");
                list.add(chainSearch);
            }
        } else {
            for (int i = 0; i < 2; i++) {
                FirstChainSearch chainSearch = new FirstChainSearch("序号：" + i, "2", "3", "4", 5444L, "6", "7", 8, 9, 10, 11, 12, 13, 14, "15", 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, "30", "31", "32", "33");
                list.add(chainSearch);
            }
        }
        DealResp deal =new DealResp();
        resultUtil.setCode(1);
        resultUtil.setNote("成功");
        AdapterResp resp = deal.adapterRespBuildFirstChainSearch(list);
        AdapterRespChild child = resp.getResultSet().get("4");
        resultUtil.setData(deal.getData(child));
        resultUtil.setTotal(list.size());
        return resultUtil;
    }


    @RequestMapping("/secondChainInfo")
    public ResultUtil getSecondChainInfo(@RequestBody SecondChainCondition condition){
        ResultUtil resultUtil = new ResultUtil();
        Pagination page = condition.getPage();
        SecondChainCondition.Condition domain = condition.getCondition();
        if(page==null){
            page = new Pagination(1,10);
        }
        if(page.getCurrent()==null){
            page.setCurrent(1);
        }
        if(page.getPageSize()==null){
            page.setPageSize(10);
        }
        List<SecondChainSearchOutputDomain> list = new ArrayList<>();
        if (domain.getG_funcid() != null) {
            for (int i = 0; i < 20; i++) {
                SecondChainSearchOutputDomain chainSearch = new SecondChainSearchOutputDomain(i,"2","3","4","5","6","7","8","9","10",11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0,21.0,22.0,23.0,24.0,25.0,26.0,27.0,28.0,29.0,30.0,31.0,32.0,33.0,34.0,
                        35.0,36.0,37.0,"38",39,40,41,42,"43","44","45",46,"47","48","49",50,"51","52");
                list.add(chainSearch);
            }
        } else {
            for (int i = 0; i < 2; i++) {
                SecondChainSearchOutputDomain chainSearch = new SecondChainSearchOutputDomain(i,"2","3","4","5","6","7","8","9","10",11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0,21.0,22.0,23.0,24.0,25.0,26.0,27.0,28.0,29.0,30.0,31.0,32.0,33.0,34.0,
                        35.0,36.0,37.0,"38",39,40,41,42,"43","44","45",46,"47","48","49",50,"51","52");
                list.add(chainSearch);
            }
        }
        DealResp deal =new DealResp();
        resultUtil.setCode(1);
        resultUtil.setNote("成功");
        AdapterResp resp = deal.adapterRespBuildSecondSearchChain(list);
        AdapterRespChild child = resp.getResultSet().get("4");
        resultUtil.setData(deal.getData(child));
        resultUtil.setTotal(list.size());
        return resultUtil;
    }

    @RequestMapping("/preChainInfo")
    public ResultUtil getPreChainInfo(@RequestBody PreChainCondition condition){
        ResultUtil resultUtil = new ResultUtil();
        Pagination page = condition.getPage();
        PreChainCondition.Condition domain = condition.getCondition();
        if(page==null){
            page = new Pagination(1,10);
        }
        if(page.getCurrent()==null){
            page.setCurrent(1);
        }
        if(page.getPageSize()==null){
            page.setPageSize(10);
        }
        List<PreChainSearchOutputDomain> list = new ArrayList<>();
        if (domain.getG_funcid() != null) {
            for (int i = 0; i < 20; i++) {
                PreChainSearchOutputDomain chainSearch = new PreChainSearchOutputDomain(i,"2","3","4","5","6","7","8","9","10","11",12.0,13.0,14.0,"15","16",17,18,"19","20","21",22.0,23.0);
                list.add(chainSearch);
            }
        } else {
            for (int i = 0; i < 2; i++) {
                PreChainSearchOutputDomain chainSearch = new PreChainSearchOutputDomain(i,"2","3","4","5","6","7","8","9","10","11",12.0,13.0,14.0,"15","16",17,18,"19","20","21",22.0,23.0);
                list.add(chainSearch);
            }
        }
        DealResp deal =new DealResp();
        resultUtil.setCode(1);
        resultUtil.setNote("成功");
        AdapterResp resp = deal.adapterRespBuildPreSearchChain(list);
        AdapterRespChild child = resp.getResultSet().get("4");
        resultUtil.setData(deal.getData(child));
        resultUtil.setTotal(list.size());
        return resultUtil;
    }

}
